//
//  JSTInterestcircleContentFrame.m
//  KYKJPackDemo
//
//  Created by 01 on 17/5/10.
//  Copyright © 2017年 ???. All rights reserved.
//

#import "JSTInterestcircleContentFrame.h"
#import "JSTInterestcircleDataModel.h"

@implementation JSTInterestcircleContentFrame

- (void)setModel:(JSTInterestcircleDataModel *)model
{
    _model = model;
    // 1.头像
    CGFloat iconX = kCurrentScreenWidth(15);
    CGFloat iconY = kCurrentScreenWidth(5);
    CGFloat iconW = kCurrentScreenWidth(20);
    CGFloat iconH = iconW;
    self.iconFrame = CGRectMake(iconX, iconY, iconW, iconH);
    
    // 2.昵称
    CGFloat nameX = CGRectGetMaxX(self.iconFrame) + kCurrentScreenWidth(5);
    CGFloat nameY = kCurrentScreenWidth(9);
    CGSize nameSize = [NSString sizeWithString:_model.userName font:kSystemFont(kCurrentScreenWidth(12)) CGsize:CGSizeMake(kDeviceWidth, MAXFLOAT)];
    self.nameFrame = (CGRect){{nameX, nameY}, nameSize};
    
    // 3.正文
    CGFloat textX = iconX;
    CGFloat textY = CGRectGetMaxY(self.iconFrame) + kCurrentScreenWidth(9);
    CGFloat maxW = kDeviceWidth - 2 * textX;
    CGSize maxSize = CGSizeMake(maxW, MAXFLOAT);
    CGSize textSize = [NSString sizeWithString:_model.contentText font:kSystemFont(kCurrentScreenWidth(10)) CGsize:maxSize];
    self.textFrame = (CGRect){{textX, textY}, textSize};
    
    self.emotTextFrame=(CGRect){{textX,textY},textSize};
    
    //  修改cell的高度
    MLEmojiLabel *label=[[MLEmojiLabel alloc] initWithFrame:self.textFrame];
    label.numberOfLines = 0;
    label.textInsets = UIEdgeInsetsMake(5, 0, 0, 0);
    label.font = kSystemFont(kCurrentScreenWidth(10));
    label.lineBreakMode = NSLineBreakByCharWrapping;
    label.isNeedAtAndPoundSign = YES;
    //label.customEmojiRegex = @"[\\[e_]+[0-9]{1,4}+[\\]]";
    label.customEmojiRegex = @"\\[[a-zA-Z0-9\\u4e00-\\u9fa5]+\\]";
    label.customEmojiPlistName = @"Emoji_icon.plist";
    [label setEmojiText:model.contentText];
    [label sizeToFit];
    self.textFrame=label.frame;
    
    // 自身
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = kDeviceWidth;
    CGFloat h = CGRectGetMaxY(self.textFrame) + EvaluationCellInset;
    self.frame = CGRectMake(x, y, w, h);
}

@end
